<template>
	<div class="commit-footer">
		<div class="addr_foot" v-if="showFooter">
			<div class="addr_foot_f">
				<div><span>当前城市：</span><span>{{CurrentCity}}</span></div>
				<div><span>当前区县：</span><span style='color: red;'>{{CurrentDistrict}}</span></div>
				<div><span>当前地址：</span><span>{{CurrentLocation}}</span></div>
			</div>
			<div class="addr_foot_s">
				<div @click="RefreshPositioning">刷新定位</div>
			</div>
		</div>
		<div class="left-countbox" v-if="showFooter">
			<div class="left-count">
				<div class="bottom">
					当前扫描:<i>{{ count.length }}</i>件
				</div>
			</div>
			<div class="commit-button-box commitAbnormal" v-if='abnormalscan'>
				<div class="commit-button" @click="checkForCommit">提交</div>
			</div>
			<div class="commit-button-box" v-if='!abnormalscan'>
				<div v-if='!abnormalscan' class="commit-button" @click="checkForCommit">提交</div>
			</div>
			<v-confirm ref="myConfirm" @userBehavior="userBehaviorFun"></v-confirm>
		</div>
		<!-- 提交前 如果没有全部扫描 提示弹出框 -->
		<div class="SelectDelivery" v-if='commitPopUp_show'>
			<div class="DeliveryBox">
				<div class="DeliveryBox_head commitPopUp_head" style="color: red;border: none;">订单未扫描完，是否提交？</div>
				<div class="DeliveryBox_content commitPopUp_content">
					<div style="border: none;"><span>订单总件数：</span><span style="color: red;">{{actualQty}}</span></div>
					<div style="border: none;"><span>当前提交数：</span><span style="color: red;">{{count.length}}</span>
					</div>
				</div>
				<div class="DeliveryBox_head commitPopUp_head" style="color: red;border: none;">请确认地址是否正确？</div>
				<div class="DeliveryBox_head commitPopUp_head" style="color: red;border: none;">不正确请刷新定位<span
						class="addr_foot_sl" @click="RefreshPositioning">刷新定位</span></div>
				<div class="DeliveryBox_content commitPopUp_content">
					<div style="border: none;"><span>当前城市：</span>{{CurrentCity}}</div>
					<div style="border: none;"><span>当前区县：</span><span style='color: red;'>{{CurrentDistrict}}</span>
					</div>
					<div style="border: none;"><span>当前地址：</span>{{CurrentLocation}}</div>
				</div>
				<div class="DeliveryBox_bottom">
					<div><span @click="commitPopUpCancel">取消</span></div>
					<div><span @click="commitPopUpConfirm">确定</span></div>
				</div>
			</div>
		</div>
		<!-- 提交前 全部扫描后 提示弹出框 -->
		<div class="SelectDelivery" v-if='AllCommitPopUp_show'>
			<div class="DeliveryBox">
				<!-- <div class="DeliveryBox_head commitPopUp_head" style="color: red;border: none;">是否提交数据？</div> -->
				<div class="DeliveryBox_head commitPopUp_head" style="color: red;border: none;">请确认地址是否正确？</div>
				<div class="DeliveryBox_head commitPopUp_head" style="color: red;border: none;">不正确请刷新定位<span
						class="addr_foot_sl" @click="RefreshPositioning">刷新定位</span></div>
				<div class="DeliveryBox_content commitPopUp_content">
					<div style="border: none;"><span>当前城市：</span>{{CurrentCity}}</div>
					<div style="border: none;"><span>当前区县：</span><span style='color: red;'>{{CurrentDistrict}}</span>
					</div>
					<div style="border: none;"><span>当前地址：</span>{{CurrentLocation}}</div>
				</div>
				<div class="DeliveryBox_bottom">
					<div><span @click="AllCcommitPopUpCancel">取消</span></div>
					<div><span @click="AllCcommitPopUpConfirm">确定</span></div>
				</div>
			</div>
		</div>
		<div v-if="ifTips" class="msg_tips">
			<div class="tips_content">
				<i class="iconfont icon-chenggong1"></i>
				<p>{{tips_Msg}}</p>
			</div>
		</div>
	</div>
</template>
<script>
	import {
        commitStowageScan
	} from "../api/api";
	import Confirm from '../components/confirm'
	import $ from 'jquery'
	export default {
		name: "PackageCommitFooter",
		components: {
			'v-confirm': Confirm
		},
		data() {
			return {
                docmHeight: document.documentElement.clientHeight, // 默认屏幕高度       
                realHeight:  0, // 实时屏幕高度 
                showFooter: true, // 显示底部fixed
				CurrentCity: '', // 当前城市
				CurrentLocation: '', // 当前地址
				CurrentDistrict: '', // 当前区县
				cleanOrderList: [],
				commitImgDialog: false,
				imageUrl: null,
				imgObj: null,
				latitude: '',
				longitude: '',
				tips_Msg: "", // 提示信息
				ifTips: false,
				crruentconfirm: "", // 是提交还是批量提交
				commitPopUp_show: false, // 提交前 如果没有全部扫描 提示弹出框
				AllCommitPopUp_show: false // 提交前 全部扫描 提示弹出框
			}
		},
		props: [
			'count', // 运单数量
			'orderCount', // 订单数量
			'countData',
			'orderList',
			'deliveryId',
			'transportLinks', // 扫描环节
			'actualQty', // 订单总件数
			'omsNo', // 订单号
			'orderId', // 订单id
			'HasLoading', // 已装车件数
			'abnormalscan', // 是否是异常签收
			'AbHasScanNum' // 异常已签收数量
        ],
        watch: {
            realHeight:function() {
                // 如果默认高度大于实际高度则影藏，反之就显示
				if (this.docmHeight > this.realHeight) {            
					this.showFooter = false        
				} else {            
					this.showFooter = true        
				}
            }
        },
		mounted() {
            this.onPlusReady('e') // 获取APP经纬度
            window.onresize = ()=>{
                return(()=>{                     
                    // 实时屏幕高度                       
                    this.realHeight = document.body.clientHeight         
                })()    
            } 
		},
		methods: {
			// 刷新定位
			RefreshPositioning() {
				this.onPlusReady('e') // 获取APP经纬度
			},
			SetCurrAddress(lngad) {
				this.ReceivingLatitud(lngad);
			},
			userBehaviorFun(type, data) {
				if (type !== 'clickCancel') {
					this.commitData()
				} else {
					this.$emit('scanFun', true)
				}
			},
			// 提交前 没有完全扫描 弹出框 消失
			commitPopUpCancel() {
				this.commitPopUp_show = false;
			},
			// 提交前 没有完全扫描 弹出框 确定
			commitPopUpConfirm() {
				this.commitPopUp_show = false;
				this.commitData();
			},
			// 提交前 完全扫描 弹出框 消失
			AllCcommitPopUpCancel() {
				this.AllCommitPopUp_show = false;
			},
			// 提交前 完全扫描 弹出框 确定
			AllCcommitPopUpConfirm() {
				this.AllCommitPopUp_show = false;
				this.commitData();
			},
			// 判断路由，提货扫描以及签收扫描弹出弹窗
			checkForCommit() {
				if (this.count.length !== 0) {
					this.onPlusReady('isLoading_')
					this.crruentconfirm = "提交";
					if (this.$route.path == '/AbnormalScan') {
						if (this.count.length < this.actualQty) {
							this.commitPopUp_show = true;
						} else {
							this.AllCommitPopUp_show = true;
						}
						return;
					}
					if (this.count.length < this.actualQty) {
						this.commitPopUp_show = true;
						return;
					}
					this.AllCommitPopUp_show = true;
					this.$emit('scanFun', false) // 关闭摄像头
				}
			},
			/**
			 * 数据提交
			 */
			commitData() {
				let that = this;
				const _this = this;
				this.commitPopUp_show = false;
				that.$emit('isLoading_', true, "拼命加载中");
				that.AllCommitPopUp_show = false;
				let path = this.$route.path;
				let linkNode = ''; // 需要传参的linkNode类别
				switch (path) {
					case '/AbnormalScan':
						linkNode = '40'
						break
					default:
						linkNode = '10'
						break
				}
				let params = {};
				params.linkNode = linkNode
				params.scanPerson = this.$store.state.userInfo.userName; // 扫描人的名称 *
				params.cellphone = this.$store.state.userInfo.cellphone; // 扫描人的电话 *
				params.longitude = this.longitude;
				params.latitude = this.latitude;
				params.city = this.CurrentCity;
				params.district = this.CurrentDistrict;
				params.address = this.CurrentLocation;
				params.params = []
				for (let key in this.count) {
					let obj = {};
					obj.omsNo = this.count[key].omsno;
					obj.labelNo = this.count[key].order;
					params.params.push(obj);
				}
				this.httpRequest1('post', commitStowageScan, params).then(res => {
                    if ($("div.uploadImg ul>li").length > 0) {
                        that.$parent.updateimg();
                    } else {
                        that.$alert(res.detail, '提示', {
                            confirmButtonText: '确定'
                        })
                    }
                    this.$emit('reflash', true)
                    this.$emit('scanFun', true)
                    this.$emit('isLoading_', false);
				}).catch(res => {
                    this.$emit('scanFun', true)
                     this.$emit('isLoading_', false);
				})
			}
		}
	}
</script>
<style scoped lang="less">
	@import "publicLess.less";
</style>